package com.houg.testorderapi.controller;

import com.houg.payapi.entity.PayInfo;
import com.houg.testorderapi.model.entity.Order;
import com.houg.testorderapi.service.GetPayService;
import com.houg.testorderapi.service.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: NALHOUG
 * @Time: 2019/11/8 16:31
 * @Explain:
 */
@RestController
public class OrderController {
    @Resource
    private OrderService orderService;
    @Resource
    private GetPayService getPayService;
    /**
     * 用户获取自己的订单
     * @param userId 用户标识
     * @return 订单对象
     */
    @RequestMapping(value = "/selectUserOrder/{userId}")
    public Order userOrder(@PathVariable String userId){
        return orderService.selectByUserId(userId);
    }

    /**
     * 取消订单
     * @param userId 用户标识
     * @param orderId 订单编号
     * @return 订单对象
     */
    @RequestMapping(value = "/del/{userId}/{orderId}")
    public int delOrder(@PathVariable String userId,@PathVariable String orderId){
        return orderService.closeOrder(orderId);
    }

    /**
     * 去支付
     * @param orderId 用户标识
     * @return 影响行数
     */
    @RequestMapping(value = "/getPay/{orderId}")
    public String getPay(@PathVariable String orderId){
        Order order = orderService.selectByOrderId(orderId);
        PayInfo payInfo = new PayInfo();
        BeanUtils.copyProperties(order,payInfo);
        return getPayService.getPay(payInfo);
    }







}
